/*
 * Equilibrator.h
 *
 *  Created on: 2 Aug 2011
 *      Author: Allan
 */

#ifndef EQUILIBRATOR_H_
#define EQUILIBRATOR_H_

// C++ includes
#include <string>
#include <vector>
#include <tuple>
using namespace std;

// Eigen includes
#include <Eigen/Core>
using namespace Eigen;

// GeoReact includes
#include "Core/EquilibriumSolver.h"
#include "Geochemistry/GeoSystem.h"

enum EquilibriumConditionType
{
	FixedMass,
	FixedTotalMass,
	FixedActivity,
	FixedAcidity,
	FixedPartialPressure,
	ChargeBalanced,
};

class Equilibrator
{
public:
	Equilibrator();
	
	void
	AddCondition(const string& type);
	
	void
	AddCondition(const string& type, double value);
	
	void
	AddCondition(const string& type, const string& species, double value);
	
	void
	ResetConditions();
	
	void
	Equilibrate(GeoSystem& system);
	
private:
	/// The equilibrium conditions as tuples (type, species, value)
	vector<tuple<string, string, double>> conditions;
	
	/// The equilibrium solver to solve the equilibrium problem
	EquilibriumSolver eSolver;
	
private:
	void 
	SetupPrimarySpecies(GeoSystem& system);
	
	void 
	SetupInitialGuess(GeoSystem& system);
	
	void 
	SetupEquilibriumSolver(const GeoSystem& system);
	
	const EquilibriumCondition
	ChargeBalancedCondition()
};

#endif /* EQUILIBRATOR_H_ */
